package org.shuzhou.b_source;

import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;


/**
 * 用到的数据集为people.txt
 */
public class DataSource {
    public static void main(String[] args) throws Exception {
        //参数检查
        if (args.length != 2) {
            System.err.println("USAGE:\nSocketPeople <hostname> <port>");
            return;
        }

        // 从端口获取数据
        String hostname = args[0];
        Integer port = Integer.parseInt(args[1]);


        // set up the streaming execution environment
        final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        // 获取数据，数据源为数组
        DataStreamSource<String> stream1 = env.fromElements(
            "王矗馨,女,汉族",
            "万俊伟,男,阿昌族",
            "包弓泰,男,东乡族",
            "庞金豪,女,汉族",
            "靳伟腾,女,汉族"
        );
        stream1.print();


        //获取数据，数据源为文本文件
        DataStream<String> text = env.readTextFile("file:///path/to/file");
        text.print();


        //获取数据，数据源为Socket端口
        DataStreamSource<String> stream2 = env.socketTextStream(hostname, port);
        stream2.print();

        
        env.execute("Flink Datasource Example");
    }
}
